<?php
/**
 * Created by PhpStorm.
 * User: meng
 * Date: 2021/7/6
 * Time: 3:07 下午
 */

namespace app\admin\validator;


use app\lib\BaseValidator;

class AdminUserValidator extends BaseValidator
{
    protected $rule = [
        'id'            => 'require|isPostInt',
        'sex'           => 'in:0,1,2',
        'status'        => 'in:1,2',
        'mobile'        => 'isMobileNumber',
        'username'      => 'require|alphaDash|length:4,20|unique:admin_user',
        'nickname'      => 'length:1,30',
        'password'      => 'require|length:6,20',
        'email'         => 'email',
        'captcha'       => 'require|length:5',
        'captcha_token' => 'require'
    ];

    protected $message = [
        'id'                 => '用户ID必填,只能为正整数',
        'sex'                => '性别只能为0,1,2',
        'status'             => '状态只能为1,2',
        'mobile'             => '手机号码不正确',
        'username.require'   => '用户名必填',
        'username.alphaDash' => '用户名只能为数字、字母、减号或下划线',
        'username.length'    => '用户名长度4-20字',
        'username.unique'    => '用户名重复',
        'nickname'           => '昵称长度只能1-30字',
        'password.require'   => '密码必填',
        'password.length'    => '密码长度最少6位,最多20位',
        'email'              => '电子邮件不正确',
        'roles'              => '请选择角色',
        'captcha'            => '验证码不正确',
        'captcha_token'      => '验证码不正确'
    ];

    protected $scene = [
        'create' => ['username', 'password', 'mobile', 'gender', 'status'],
        'update' => ['id', 'nickname', 'mobile', 'gender', 'status', 'email']
    ];
}
